<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/include/tagLib.jsp" %>
<!doctype html>
<html lang="en">
<head>
    <title>${sieName}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <%@include file="/include/cssLib.jsp" %>
</head>

<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-md-12">
            <!-- 菜单 -->
            <tag:nav key="sysAdmin"/>

            <div class="tab-content">
                <div class="tab-pane active">
                    <div class="card col-md-10 col-md-offset-1">
                        <tag:sys-nav key="noticeList"/>
                        <div class="card-content">

                            <div class="row">
                                <label class="col-sm-2 label-on-left"></label>
                                <div class="col-sm-6">
                                    <h4>新增公告</h4>
                                </div>
                            </div>
                            <form id="noticeFormId" method="post" action="#" class="form-horizontal" onsubmit="return submitFun()">
                                <div class="card-content2">
                                    <div class="row">
                                        <label class="col-sm-2 label-on-left">主题</label>
                                        <div class="col-sm-6">
                                            <div class="form-group label-floating">
                                                <input type="text" name="subject" class="form-control clearable" required="true">
                                                <span class="help-block">A block of help text that breaks onto a new line.</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-2 label-on-left">公告类型</label>
                                        <div class="col-sm-6">
                                            <div class="radio checkbox-inline">
                                                <label>
                                                    <input type="radio" name="type" value="normal" checked>普通公告
                                                </label>
                                            </div>
                                            <div class="radio checkbox-inline">
                                                <label>
                                                    <input type="radio" name="type" value="update">升级公告
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-2 label-on-left">内容</label>
                                        <div class="col-sm-6">
                                            <div class="form-group label-floating">
                                                <label class="control-label"></label>
                                                <textarea name="content" class="form-control clearable" rows="4" required="true"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-2 label-on-left">展示类型</label>
                                        <div class="col-sm-6">
                                            <div class="radio checkbox-inline">
                                                <label>
                                                    <input type="radio" name="showType" value="headtip" checked>头部提示
                                                </label>
                                            </div>
                                            <div class="radio checkbox-inline">
                                                <label>
                                                    <input type="radio" name="showType" value="alert">弹窗
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-2 label-on-left">有效时间</label>
                                        <div class="col-sm-10">
                                            <div class="row">
                                                <div class="col-md-3">
                                                    <div class="form-group label-floating">
                                                        <label class="control-label"></label>
                                                        <input type="datetime" id="startTime" class="form-control" name="startTime" required="true" placeholder="开始时间">
                                                    </div>
                                                </div>
                                                <div class="col-md-4">
                                                    <div class="form-group label-floating">
                                                        <label class="control-label"></label>
                                                        <input type="datetime" id="endTime" class="form-control" name="endTime" required="true" placeholder="结束时间">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-2 label-on-left">状态</label>
                                        <div class="col-sm-10">
                                            <div class="form-group label-floating"style="padding-top: 15px;">
                                                <input name="status" class="bootstrap-switch" type="checkbox" value="1" data-toggle="switch" checked="" data-on-label="有效" data-off-label="无效">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-md-2"></label>
                                        <div class="col-md-10">
                                            <div class="form-group form-button">
                                                <button type="submit" class="btn btn-fill btn-rose">提 交</button>

                                                &nbsp;&nbsp;
                                                <a href="${ctx}/adminConsole/system/noticeList" class="btn btn-simple">返回</a>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%@include file="/include/sidebarRight.jsp" %>
</body>
<%@include file="/include/scriptLib.jsp" %>
<%@include file="/include/validScriptLib.jsp" %>
<script type="text/javascript">
    $(document).ready(function() {
        setFormValidation('#noticeFormId');
        //日期时间范围
        laydate.render({
            elem: '#startTime'
            ,type: 'datetime'
            ,min: 0
            ,done: function(value, date, endDate){
                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                var endTime = $("#endTime").val();
                if(CommUtil.isNotEmpty(endTime)){
                    log(endTime);
                    var eTime = DateUtil.strToDate(endTime).getTime();
                    var sTime = DateUtil.strToDate(value).getTime();
                    if(sTime >= eTime){
                        alert("开始时间必须小于结束时间");
                        setTimeout(function(){
                            $("#startTime").val('');
                        }, 200);
                    }
                }
            }
        });
        laydate.render({
            elem: '#endTime'
            ,type: 'datetime'
            ,min: 0
            ,done: function(value, date, endDate){
                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                var startTime = $("#startTime").val();
                if(CommUtil.isNotEmpty(startTime)){
                    log(startTime);
                    var sTime = DateUtil.strToDate(startTime).getTime();
                    var eTime = DateUtil.strToDate(value).getTime();
                    if(sTime >= eTime){
                        alert("结束时间必须大于开始时间");
                        setTimeout(function(){
                            $("#endTime").val('');
                        }, 200);
                    }
                }
            }
        });
    });

    function submitFun(){
        var form = $("#noticeFormId");
        if(!form. valid()){
            return false;
        }

        var paramArr = form.serialize()
        HttpUtil.ajaxAsyncJsonPost("/adminConsole/system/addNotice", paramArr, function(message){
            dialogTip(message);
            refreshPage(1500, '${ctx}/adminConsole/system/noticeList');
        });
        return false;
    }

</script>

</html>